package sdk.pay.model;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;

import java.net.URISyntaxException;

import sdk.pay.basepay.UnifiedPay;
import sdk.pay.utils.PayExceptionUtil;
import sdk.pay.utils.PayLogUtil;

/**
 * Created by Administrator on 2017/5/22.
 */

public class WapPay extends UnifiedPay {

    public WapPay(String content, Context context) {
        super(content, context);
    }


    @Override
    public void pay(CallBack callBack) {
        mCallBack = callBack;
        wapPay();
    }

    private void wapPay() {
        Intent intent;
        PayLogUtil.logBase("wapPay url = " + getContent());
        try {
            intent = Intent.parseUri(getContent(), Intent.URI_INTENT_SCHEME);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setComponent(null);
            intent.setSelector(null);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        } catch (URISyntaxException | ActivityNotFoundException e) {
            e.printStackTrace();
            PayExceptionUtil.getInstance().saveExceptionFile("wapPay exception message = " + e.getMessage());
        } finally {
            prepareLeave();
        }
    }
}
